#pragma once
#include"Hash.h"

namespace Unordered_set {
	template<class K>
	class KeyOfT {
	public:
		const K& operator()(const K& key) {
			return key;
		}
	};

	template<class K>
	class unordered_set {
	protected:
		HashTable<K, K, KeyOfT<K>> _ht;
	public:
		typedef  typename HashTable<K, K, KeyOfT<K>>::const_iterator iterator;
		typedef  typename HashTable<K, K, KeyOfT<K>>::const_iterator const_iterator;
	public:
		pair<iterator,bool> Insert(const K& key) {
			//return _ht.Insert(key);
			pair<typename HashTable<K, K, KeyOfT<K>>::iterator, bool> ret = _ht.Insert(key);
			return pair<iterator, bool>(ret.first, ret.second);
		}

		bool Erase(const K& key) {
			return _ht.Erase(key);
		}

		iterator begin()const {
			return _ht.begin();
		}

		iterator end()const {
			return _ht.end();
		}

		void print() {
			for (size_t i = 0; i < _ht._table.size(); ++i) {
				cout << i << ":";
				HashData<K>* cur = _ht._table[i];
				while (cur) {
					printf("%d ->", cur->_data);
					cur = cur->_next;
				}
				putchar('\n');
			}
		}
	};
}
